﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Juli.Mes.VisionDemo.Helper
{
    public static class RandomValueHelper
    {

        public enum EnumDateType
        {
            None = 0,
            Integer = 1,
            Double = 2,
            Float = 3,
            String = 4,
            Boolean = 5

        }

        /// <summary>
        /// 随机生成整数
        /// </summary>
        /// <param name="max"></param>
        /// <param name="min"></param>
        /// <returns></returns>
        public static int Get_intRandom(int max, int min)
        {
            Random rd = new Random();
            return rd.Next(min, max + 1);
        }

        /// <summary>
        /// 随机生成指定范围的字符串
        /// </summary>
        /// <param name="arr"></param>
        /// <returns></returns>
        public static string Get_stringRandom(List<string> arr)
        {
            Random ran = new Random();

            int n = 0;
            if (arr.Count - 1 == 1)
            {
                n = ran.Next(2);
            }
            else
            {
                n = ran.Next(arr.Count - 1);
            }

            return arr[n];
        }

        /// <summary>
        /// 随机生成字符串
        /// </summary>
        /// <param name="n"></param>
        /// <param name="Number"></param>
        /// <param name="Lowercase"></param>
        /// <param name="Capital"></param>
        /// <returns></returns>
        public static string Get_charRandom(int n = 10, bool number = true, bool lowercase = true, bool capital = true)  // 生成随机字符串
        {
            StringBuilder tmp = new StringBuilder();
            Random rand = new Random();
            string characters = (capital ? "ABCDEFGHIJKLMNOPQRSTUVWXYZ" : null) + (number ? "0123456789" : null) + (lowercase ? "abcdefghijklmnopqrstuvwxyz" : null);

            if (characters.Length < 1)
            {
                return (null);
            }

            for (int i = 0; i < n; i++)
            {
                tmp.Append(characters[rand.Next(0, characters.Length)].ToString());
            }

            return (tmp.ToString());
        }

        /// <summary>
        /// 随机生成Bool
        /// </summary>
        /// <returns></returns>
        public static bool Get_boolRandom()
        {
            bool[] arr = { true, false };
            Random ran = new Random();
            return arr[ran.Next(2)];
        }

        /// <summary>
        /// 随机生成小数
        /// </summary>
        /// <param name="max"></param>
        /// <param name="min"></param>
        /// <returns></returns>
        public static double Get_doubleRandom(int max, int min)
        {
            Random ran = new Random();

            return (double) ran.Next(min, max) / 10000;

        }
    }
}
